<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.Map,java.util.Date,java.text.SimpleDateFormat;"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<fieldset>
	<legend>
		&nbsp;&nbsp;&nbsp;&nbsp;
		<c:if test="${p eq 'edit' }">修改</c:if>
		<c:if test="${p eq 'add' }">新建</c:if>
	</legend>
	<form class="form-horizontal"
		action='<%=request.getContextPath()%>/c?<c:out value="${ model.m_action }"/>&m_id=${model.m_id}&o=${p}&v=${v}&pri=${pri}&key=${key}&isajax=<c:if test="${tm eq null }">1</c:if><c:if test="${tm ne null }">0</c:if>'
		class='<c:out value="${ model.m_attr_class }"/>' method="post"
		<c:out value="${ model.m_attr_other }"/>
		id='<c:out value="${ model.m_attr_id }"/>'>
		<%
			Object o = request.getAttribute("e");
			Map<String, Object> e = null;
			if (null != o) {
				e = (Map<String, Object>) o;
			}
		%>
		<c:forEach var="control" items="${controls }">
			<c:set var="attr_name" value="${control.mc_attr_name }"
				scope="request" />
			<c:set var="dft_val" value="${control.mc_dft_val }" scope="request" />
			<%
				Object obj_attr_val = null;
					//输出修改值
					if (e != null) {
						obj_attr_val = e.get(request.getAttribute("attr_name")
								.toString());
						//输出默认值
					} else {
						obj_attr_val = request.getAttribute("dft_val");
						String dft_val = obj_attr_val != null ? obj_attr_val
								.toString() : null;

						if (null != dft_val) {
							// #:从session中获取值
							// $：从request中获取值
							// #user.ui_id 从session中获取 user键值的ui_id属性
							if (dft_val.startsWith("#")) {
								dft_val = dft_val.substring(1);
								int pos = dft_val.indexOf(".");
								//直接取数
								if (pos < 0) {
									obj_attr_val = session.getAttribute(dft_val);
								} else {
									//有二级
									obj_attr_val = ((Map<String, Object>) session
											.getAttribute(dft_val.substring(0, pos)))
											.get(dft_val.substring(pos + 1));
								}
							}else if("time".equals(dft_val)){
								//
								SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
								obj_attr_val = df.format(new Date());
							}else if("date".equals(dft_val)){
								//
								SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
								obj_attr_val = df.format(new Date());
							}
						}
					}
					request.setAttribute("attr_val", obj_attr_val);
			%>
			<c:choose>
				<c:when test="${control.c_tag eq 'createdate'}">
					<c:if test="${p == 'add'}">
						<input type="hidden" name="${control.mc_attr_name }"
							value="${attr_val }" />
					</c:if>
				</c:when>
				<c:when test="${control.c_tag eq 'updatedate'}">
					<input type="hidden" name="${control.mc_attr_name }"
						value="${attr_val }" />
				</c:when>
				<c:when test="${control.c_tag eq 'hidden'}">
					<input type="hidden" name="${control.mc_attr_name }"
					value="${attr_val }" />
				</c:when>
			</c:choose>
			<c:if test="${control.mc_auto == 0}">
				<c:if test="${control.mc_edit == 1}">
					<c:if test="${control.c_tag ne 'hidden'}">
						<div class="control-group">
							<label class="control-label">${control.mc_prompt }:</label>
							<div class="controls">
								<span class="${control.c_attr_class }"> <c:choose>
										<c:when test="${control.c_tag eq 'textarea'}">
											<textarea name="${control.mc_attr_name }" class="txtarea">${attr_val }</textarea>
										</c:when>
										<c:when test="${control.c_tag eq 'file'}">
											<input type="text" class="file-input" name="${control.mc_attr_name }" class="field"
												value="${attr_val }" />
											<input type="hidden" id="${control.mc_attr_name }-guid" name="guid" value=""/>
											<input type="hidden" id="${control.mc_attr_name }-ext" name="file_type" value=""/>
										</c:when>
										<c:when test="${control.c_tag eq 'date'}">
											<input type="text" name="${control.mc_attr_name }"
												class="field date-picker" value="${attr_val }" />
										</c:when>
										<c:when test="${control.c_tag eq 'password'}">
											<input type="password" name="${control.mc_attr_name }"
												class="field" value="${attr_val }" />
										</c:when>
										<c:when test="${control.c_tag eq 'ynradio'}">
											<input class="yncheckbox" type="checkbox"  <c:if test="${attr_val == 1}">checked='checked'</c:if>/>
											<input type="hidden"  name="${control.mc_attr_name }"
												class="ynradio" value="${attr_val }" />
										</c:when>
										<c:when test="${control.c_tag eq 'select'}">
											<select name="${control.mc_attr_name }" class="">${control.mc_ds}</select>
										</c:when>
										<c:when test="${control.c_tag eq 'radio'}">
											<input type="radio" name="${control.mc_attr_name }" value="1" <c:if test="${attr_val == 1 or attr_val eq null}">checked='checked'</c:if>/>
											<input type="radio" name="${control.mc_attr_name }" value="0" <c:if test="${attr_val == 0}">checked='checked'</c:if>/>
										</c:when>
										<c:otherwise>
											<input type="${control.c_tag }"
												name="${control.mc_attr_name }" class="field"
												value="${attr_val }" />
										</c:otherwise>
									</c:choose>
								</span>
							</div>
						</div>
					</c:if>
				</c:if>
			</c:if>
		</c:forEach>
		<div class="form-actions">
			<button class="btn btn-primary btn-ajax-save" o="${p }" isajax="<c:if test="${tm eq null }">1</c:if><c:if test="${tm ne null }">0</c:if>">
				<i class="icon-save"></i> <span>保存</span>
			</button>
			<button class="btn btn-back">
				<i class="icon-reply"></i> <span>返回</span>
			</button>
		</div>
	</form>
</fieldset>
<script type="text/javascript">
	$(".date-picker").datepicker();
</script>

<!-- Modal -->
<div class="modal fade" id="uploadForm" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" id="myModalLabel">附件上传</h4>
			</div>
			<div class="modal-body">
				<form action="<%=request.getContextPath()%>/f?o=upload" enctype='multipart/form-data' method="POST">
					<div id="spinner-div"><i class="icon-spinner icon-spin"></i></div>
					<input type="file" name="attach_file" />
					<button class="btn btn-primary btn-lg" type="button"><i class="icon-upload"></i> 确定</button>
					<button class="btn btn-danger btn-lg" type="button"><i class="icon-remove"></i> 取消</button>
				</form>
			</div>
			
		</div> <!-- /.modal-content -->
	</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->

